package com.opo5.logisticsmanagement.service.impl;



import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.opo5.logisticsmanagement.Vo.StatisCarVo;
import com.opo5.logisticsmanagement.common.R;
import com.opo5.logisticsmanagement.dao.VehicleListDao;
import com.opo5.logisticsmanagement.domain.VehicleList;
import com.opo5.logisticsmanagement.service.VehicleListService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VehicleListImpl extends ServiceImpl<VehicleListDao, VehicleList> implements VehicleListService {
    @Autowired
    private VehicleListDao vehicleListDao;




    @Override
    public IPage<VehicleList> selectPage(int currentPage, int pageSize, VehicleList vehicleList) {
        LambdaQueryWrapper<VehicleList>lqw=new LambdaQueryWrapper<>();
        lqw.eq(Strings.isNotEmpty(vehicleList.getLicensePlate()),VehicleList::getLicensePlate,vehicleList.getLicensePlate());
        lqw.eq(Strings.isNotEmpty(vehicleList.getState()),VehicleList::getState,vehicleList.getState());
        lqw.like(Strings.isNotEmpty(vehicleList.getVehicleType()),VehicleList::getVehicleType,vehicleList.getVehicleType());
        IPage<VehicleList>page=new Page<>(currentPage,pageSize);
        vehicleListDao.selectPage(page,lqw);
        return page;
    }



    @Override
    public R statisCar(Integer currentPage, Integer pageSize, String year) {
        Page<StatisCarVo> page = new Page<>(currentPage,pageSize);
        QueryWrapper<StatisCarVo> queryWrapper = new QueryWrapper<>();


        vehicleListDao.selectcar(currentPage,pageSize,year);
        List<StatisCarVo> cars = page.getRecords();
        return R.success(new R().add("cars",cars).add("total",page.getTotal()).getMap());
    }
}
